/**
 * 
 */
package com.eis.thirdsys.connector;

import com.eis.thirdsys.connector.conf.ConnectorConfig;
import com.eis.thirdsys.connector.datatype.DataTypeList;

/**
 * 
 * 
 * @author panwei
 *
 */
public class ThirdSysConnectorFactory {
	private ConnectorStatics connectorStatics;
	
	public ThirdSysConnectorFactory(ConnectorStatics connectorStatics) {
		this.connectorStatics = connectorStatics;
	}
	
	public ConnectorStatics getConnectorStatics() {
		return connectorStatics;
	}
	
	public ThirdSysConnectorFactory(String connectorStaticsClassName) throws Exception {
		@SuppressWarnings("unchecked")
		Class<? extends ConnectorStatics> c 
			= (Class<? extends ConnectorStatics>) Class.forName(connectorStaticsClassName);
			
		this.connectorStatics = c.newInstance();
	}
	
	/**
	 * 
	 * @param className
	 * @param connectorConfig
	 * @return
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 */
	public ThirdSysConnector newInstance(ConnectorConfig connectorConfig) 
			throws Exception {
		Class<? extends ThirdSysConnector> c = connectorStatics.getConnectorClass();
		
		ThirdSysConnector newConnector = c.newInstance();
		
		newConnector.init(connectorConfig);
		
		return newConnector;
	}
	
	public DataTypeList newDataTypeList() throws Exception {
		Class<? extends DataTypeList> c = connectorStatics.getDataTypeListClass();
		
		DataTypeList newList = c.newInstance();
		
		return newList;
	}
	
	public ConnectorConfig newConnectorConfig() throws Exception {
		Class<? extends ConnectorConfig> c = connectorStatics.getConfigClass();
		
		ConnectorConfig newConnectorConfig = c.newInstance();
		
		return newConnectorConfig;
	}
}
